package main

import (
	"fmt"
	"reflect"
)

type Person struct {
	Name string `json:"name" test:"testname"`
	Age  int    `json:"age" test:"testage"`
}

func main() {
	p := Person{
		Name: "小米",
		Age:  16,
	}

	reflectType := reflect.TypeOf(p)

	//遍历成员属性
	for i := 0; i < reflectType.NumField(); i++ {
		field := reflectType.Field(i)

		//判断Tag名称，如果是json，就打印出来
		if jsonItem, ok := field.Tag.Lookup("json"); ok {
			fmt.Println(jsonItem)
		}

		//获取Tag叫test的名称
		testItem := field.Tag.Get("test")
		fmt.Println(testItem)
	}
}
